<template>
  <div class="app-container">
    <div class="detailBox">
      <div class="touImg">
        <img v-if="form.avatar" :src="form.avatar" alt="">
        <img v-else src="../../static/avant.png" alt="" />
        <div class="name">{{form.nickName}}</div>
      </div>
      <div class="infoBox">
        <div class="list">
          <div class="lable">姓名：</div>
          <div class="content">{{form.name}}</div>
        </div>
        <div class="list">
          <div class="lable">手机号：</div>
          <div class="content">{{form.phoneNumber}}</div>
        </div>
        <!-- <div class="list">38000
          <div class="lable">会员等级：</div>
          <div class="content">
            <dict-tag :options="levelType" :value="form.levelType" />
          </div>
        </div> -->

        <!-- <div class="list">
          <div class="lable">推荐用户数量：{{form.referrerCount}}</div>
          <div class="content"></div>
        </div> -->
        <div class="list">
          <div class="lable">实名认证：</div>
          <div class="content" v-if="form.name && form.idCard">{{form.name}}({{form.idCard}})</div>
          <div class="icon" v-else>未实名</div>
        </div>
        <!-- <div class="list">
          <div class="lable">银行卡信息：</div>
          <div class="content" v-if="form.bankName && form.bankNo">{{form.bankName}}({{form.bankNo}})</div>
          <div class="icon" v-else>未上传</div>
        </div> -->
        <div class="list">
          <div class="lable">注册时间：</div>
          <div class="content">{{form.createTime}}</div>
        </div>
        <div class="list">
          <div class="lable">钱包地址：</div>
          <div class="content">{{form.blockchainAddress}}</div>
        </div>
      </div>
    </div>
    <!-- 预付卡 -->
    <div class="tableBox" v-if="type==0">
      <el-table v-loading="loading" :data="cardList" stripe border>
        <el-table-column label="序号" type="index" width="55" align="center" fixed />
        <el-table-column label="预付卡卡名称" align="center" prop="name" :show-overflow-tooltip="true" />
        <el-table-column label="卡类型" align="center" prop="cardType" :show-overflow-tooltip="true">
          <template slot-scope="scope">
            <dict-tag :options="cardClassType" :value="scope.row.cardType" />
          </template>
        </el-table-column>
        <el-table-column label="购卡时间" align="center" prop="createTime" :show-overflow-tooltip="true" />
        <el-table-column label="购卡金额" align="center" prop="rechargeTotal" :show-overflow-tooltip="true" />
        <el-table-column label="卡面值" align="center" prop="buyMoney" :show-overflow-tooltip="true">
          <template slot-scope="scope">
            <!-- <div v-if="scope.row.cardType == 2">{{scope.row.buyMoney}}次</div>
            <div v-if="scope.row.cardType == 3">￥{{scope.row.buyMoney}}</div>
            <div v-if="scope.row.cardType == 8">{{scope.row.buyMoney}}天</div> -->
            <div>￥{{scope.row.buyMoney}}</div>
          </template>
        </el-table-column>
        <el-table-column label="卡余额" align="center" prop="balanceMoney" :show-overflow-tooltip="true">
          <template slot-scope="scope">
            <div v-if="scope.row.cardType == 2||scope.row.cardType == 8">{{scope.row.balanceMoney}}次</div>
            <div v-if="scope.row.cardType == 3">￥{{scope.row.balanceMoney}}</div>
            <div v-if="scope.row.cardType == 9">{{scope.row.balanceMoney}}天</div>
          </template>
        </el-table-column>
        <el-table-column label="有效期" align="center" prop="validityType" :show-overflow-tooltip="true">
          <template slot-scope="scope">
            <span v-if="scope.row.cardType == 9">{{scope.row.usableCount}}天</span>
            <span v-else-if="scope.row.validityType==2">{{scope.row.validityEndTime}}</span>
            <dict-tag :options="validityType" :value="scope.row.validityType" v-else-if="scope.row.validityType!=2" />
          </template>
        </el-table-column>
        <el-table-column label="有效期截止" align="center" prop="validityEndTime" :show-overflow-tooltip="true" />
        <el-table-column label="卡状态" align="center" prop="status" :show-overflow-tooltip="true">
          <template slot-scope="scope">
            <dict-tag :options="cardStatus" :value="scope.row.status" />
          </template>
        </el-table-column>
        <el-table-column label="使用记录" align="center" width="120" class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <el-button size="mini" type="text" @click="handleLook(scope.row,0)">查看</el-button>
          </template>
        </el-table-column>
      </el-table>
      <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
        @pagination="getList" />
    </div>
    <!-- 数字权益卡 -->
    <div class="tableBox" v-if="type==1">
      <el-table v-loading="loading" :data="numList" stripe border>
        <el-table-column label="序号" type="index" width="55" align="center" fixed />
        <el-table-column label="卡编号" align="center" prop="cardNo" :show-overflow-tooltip="true" />
        <el-table-column label="数字权益卡名称" align="center" prop="name" :show-overflow-tooltip="true" />
        <el-table-column label="发行方" align="center" prop="merchantName" :show-overflow-tooltip="true" />
        <el-table-column label="卡图片" align="center" prop="createTime" :show-overflow-tooltip="true">
          <template slot-scope="scope">
            <img class="card_img" :src="scope.row.img" alt="" v-if="scope.row.img">
          </template>
        </el-table-column>
        <el-table-column label="单价（￥）" align="center" prop="price" :show-overflow-tooltip="true" />
        <el-table-column label="门店权益数" align="center" prop="equityNumber" :show-overflow-tooltip="true" />
        <el-table-column label="上链时间" align="center" prop="chainTime" :show-overflow-tooltip="true" />
        <el-table-column label="持卡天数" align="center" prop="holdDay" :show-overflow-tooltip="true" />
        <el-table-column label="操作" align="center" width="120" class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <el-button size="mini" type="text" @click="numCardLook(scope.row)">卡详情</el-button>
            <!-- <el-button size="mini" type="text" @click="handleLook(scope.row,1)(scope.row)">打卡记录</el-button> -->
          </template>
        </el-table-column>
      </el-table>
      <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
        @pagination="getEquityCardList" />
    </div>
    <!-- 数字权益卡 -->
    <div class="tableBox" v-if="type==2">
      <el-table v-loading="loading" :data="numList" stripe border>
        <el-table-column label="序号" type="index" width="55" align="center" fixed />
        <el-table-column label="卡编号" align="center" prop="cardNo" :show-overflow-tooltip="true" />
        <el-table-column label="数字权益卡名称" align="center" prop="name" :show-overflow-tooltip="true" />
        <el-table-column label="发行方" align="center" prop="merchantName" :show-overflow-tooltip="true" />
        <el-table-column label="卡图片" align="center" prop="createTime" :show-overflow-tooltip="true">
          <template slot-scope="scope">
            <img class="card_img" :src="scope.row.img" alt="" v-if="scope.row.img">
          </template>
        </el-table-column>
        <el-table-column label="单价（￥）" align="center" prop="price" :show-overflow-tooltip="true" />
        <el-table-column label="上链时间" align="center" prop="chainTime" :show-overflow-tooltip="true" />
        <el-table-column label="持卡天数" align="center" prop="holdDay" :show-overflow-tooltip="true" />
        <el-table-column label="操作" align="center" width="120" class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <el-button size="mini" type="text" @click="numCardLook(scope.row)">卡详情</el-button>
          </template>
        </el-table-column>
      </el-table>
      <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
        @pagination="getEquityCardList" />
    </div>
    <Dialog ref="dialog" @refresh="getList"></Dialog>
    <NumDialog ref="numCardDialog" @refresh="getList"></NumDialog>
  </div>
</template>
<script>
  import {
    adminDict,
    getCustomer,
    getCustomerCard,
    equityCardList,
    addCustomer,
    updateCustomer
  } from "@/api/members";
  import Dialog from "@/views/members/dialog";
  import NumDialog from "@/views/members/numDialog";
  export default {
    // dicts: ['customer_level_type', 'asset_card_class_type', 'asset_card_type', "customer_card_status",
    //   "asset_card_validity_type"
    // ],
    components: {
      Dialog,
      NumDialog
    },
    data() {
      return {
        loading: false,
        total: 0,
        type: 0, //0:预付卡详情，1：权益卡详情
        form: {},
        cardList: [], //预付卡
        numList: [], //数字权益卡
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          id: '',
        },
        levelType: [],
        cardClassType: [],
        validityType: [],
        cardStatus: [],
      };
    },

    created() {
      let query = this.$route.query;
      console.log(query.id);
      this.queryParams.id = query.id;
      this.type = query.type
      this.getlinkagelist()
      this.getInfo()
      if (this.type == 0) {
        this.getList()
      } else {
        this.getEquityCardList()
      }
    },
    methods: {
      getlinkagelist() {
        //获取商户类型字典
        const params = {
          // dictType: "customer_level_type,asset_card_type,asset_card_validity_type,customer_card_status",
          dictType: "asset_card_type,asset_card_validity_type,customer_card_status",
        };
        adminDict(params).then((res) => {
          // this.levelType = res.result[0].dictList;
          // this.cardClassType = res.result[1].dictList;
          // this.validityType = res.result[2].dictList;
          // this.cardStatus = res.result[3].dictList;
          this.cardClassType = res.result[0].dictList;
          this.validityType = res.result[1].dictList;
          this.cardStatus = res.result[2].dictList;
        });
      },
      getInfo() {
        getCustomer(this.queryParams.id).then(response => {
          this.form = response.data;
        });
      },
      //获取预付卡列表
      getList() {
        this.loading = true;
        getCustomerCard(this.queryParams).then(response => {
          this.total = response.total
          this.cardList = response.rows
          this.loading = false;
        });
      },
      // 获取数字权益卡列表
      getEquityCardList() {
        this.loading = true;
        equityCardList(this.queryParams).then(response => {
          this.total = response.total
          this.numList = response.rows
          this.loading = false;
        });
      },
      //预付卡查看
      handleLook(row, type) {
        this.$refs.dialog.open(row.customerId, row.id, type);
      },
      //数字权益卡查看
      numCardLook(row) {
        this.$refs.numCardDialog.open(row.id, row.equityCardId);
      },
    }
  };

</script>
<style lang="scss" scoped>
  // .app-container {
  //     background: #f5f5f5 !important;
  // }
  .detailBox {
    border-radius: 12px;
    padding: 20px;
    background: #fff;
    display: flex;
    justify-content: flex-start;
    align-items: center;

    .touImg {
      display: flex;
      flex-direction: column;
      align-items: center;

      img {
        width: 50px;
        height: 50px;
        border-radius: 50%;
      }

      .name {
        margin-top: 10px;
        font-size: 18px;
        font-weight: 500;
        color: #333;
      }
    }
  }

  .infoBox {
    display: flex;
    justify-content: flex-start;
    align-items: center;
    flex-wrap: wrap;
    flex: 1;
    margin-left: 24px;

    .list {
      width: 33.3%;
      display: flex;
      justify-content: flex-start;
      align-items: center;
      font-size: 14px;
      color: #333;
      margin-top: 10px;

      .content {
        display: flex;
        flex: 1;
      }
    }
  }

  .icon {
    background: #ccc;
    color: #fff;
    font-size: 12px;
    height: 20px;
    line-height: 20px;
    padding: 0 8px;
    border-radius: 2px;
  }

  .card_img {
    width: 100px;
    height: 60px;
  }

  .tableBox {
    background-color: #fff;
    padding: 20px;
    border-radius: 8px;
    margin-top: 20px;
  }

</style>
